from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from webdriver_manager.firefox import GeckoDriverManager


class DriverConfig:

    @staticmethod
    def driver_config():
        """

        :return:返回配置好的Firefox WebDriver实例
        """
        options = Options()
        # options.add_argument('-headless')  # 不启用GUI
        options.add_argument('--incognito')  # 无痕模式

        # 实例化浏览器驱动
        service = Service(GeckoDriverManager().install())
        driver = webdriver.Firefox(service=service, options=options)

        # 设置窗口大小（在WebDriver中设置）
        driver.set_window_size(1920, 1080)

        # 隐式等待时间
        driver.implicitly_wait(5)

        # 删除所有cookies
        driver.delete_all_cookies()
        return driver


if __name__ == '__main__':
    DriverConfig().driver_config()
    # test_driver = DriverConfig().driver_config()
    # test_driver.get("https://www.baidu.com")
